package com.example.recyclertest119chd;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter myAdapter;

    List<ArticleBean>list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView=(RecyclerView)findViewById(R.id.recycleView);

        layoutManager=new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        list=getData();
        myAdapter=new MyAdapter(this);
        myAdapter.setList(list);
        recyclerView.setAdapter(myAdapter);
    }
    private List<ArticleBean> getData(){
        List<ArticleBean>list=new ArrayList<ArticleBean>();
        ArticleBean articleBean;

        articleBean=new ArticleBean();
        articleBean.setArticleId(1);
        articleBean.setTitle("title 1");
        articleBean.setImgid(R.drawable.f1);
        articleBean.setTitle("2017-5-15");
        articleBean.setDescription("11");
        list.add(articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(2);
        articleBean.setTitle("title 2");
        articleBean.setImgid(R.drawable.f2);
        articleBean.setTitle("2017-5-15");
        articleBean.setDescription("11");
        list.add(articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(3);
        articleBean.setTitle("title 3");
        articleBean.setImgid(R.drawable.f3);
        articleBean.setTitle("2017-5-15");
        articleBean.setDescription("11");
        list.add(articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(4);
        articleBean.setTitle("title 4");
        articleBean.setImgid(R.drawable.f4);
        articleBean.setTitle("2017-5-15");
        articleBean.setDescription("11");
        list.add(articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(5);
        articleBean.setTitle("title 5");
        articleBean.setImgid(R.drawable.f5);
        articleBean.setTitle("2017-5-15");
        articleBean.setDescription("11");
        list.add(articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(6);
        articleBean.setTitle("title 6");
        articleBean.setImgid(R.drawable.f6);
        articleBean.setTitle("2017-5-15");
        articleBean.setDescription("11");
        list.add(articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(7);
        articleBean.setTitle("title 7");
        articleBean.setImgid(R.drawable.f1);
        articleBean.setTitle("2017-5-15");
        articleBean.setDescription("11");
        list.add(articleBean);
        return list;
    }
}
